/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Bank;
import java.util.*;
import simframe.simulation.*;
/**
 *
 * @author karakots
 */
public class BankMarket extends SimObject {

    private List<Bank> banks = new ArrayList<Bank>();

    public boolean dead() {
        return false;
    }

    public void reset() {
    }

    public void addBank(Bank b) {
        banks.add(b);
    }

    public Bank getGoodBigBank(Bank sourceBank) {
        Bank destBank = null;
        double maxEquity = 0;
        
        for (Bank b: banks) {
            if (!b.getFailed()) {
                double equity = b.getEquity();
                if (equity > maxEquity) {
                    maxEquity = equity;
                    destBank = b;
                }
            }
        }
        return destBank;
    }

    public Bank selectSavingsBankBasedOnDeposits() {
        Bank selBank = null;
        double randomNumber = Math.random();
        double thresh;
        for (Bank b: banks) {
            thresh = b.getMyPctThreshold();
            if (randomNumber <= thresh)
                return b;
            selBank = b;
        }
        return selBank;
    }
}
